﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc @Copy Right 2019
// 文件： GovRoleRepository.cs
// 项目名称：斑马车务
// 创建时间：2019-01-09
// 负责人：lsc
// ===================================================================
using System;
using System.Text;
using System.Collections.Generic;
using CGT.Infrastructure.Entity;
using Dapper.Extensions;
using CGT.Infrastructure.Model;

namespace CGT.Infrastructure.Repository
{
	/// <summary>
	///角色 仓储层
	/// </summary>	
	public class GovRoleRepository:BaseRepository<GovRole>
	{		
    
        #region 构造

        public GovRoleRepository() : base(){}

        public GovRoleRepository(string connectionString) : base(connectionString){}

        public GovRoleRepository(DatabaseContext dbContext) : base(dbContext){}

        #endregion

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public Page<GovRoleModel> GetPages(long pageIndex,long pageSize)
        {
            string sql = "SELECT r.*,t.TypeName FROM[GovRole] r with(nolock)inner join GovRoleType t with(nolock) on r.RoleTypeID = t.RoleTypeID where r.IsActive = 1";
            return dbContext.Connection.Page<GovRoleModel>(pageIndex, pageSize, sql);
        }

        /// <summary>
        /// 名称是否重复
        /// </summary>
        /// <returns></returns>
        public bool CheckRoleName(string name)
        {
            string sql = "select * from GovRole where IsActive=1 and RoleName=@RoleName";
            return ExecuteScalar<int>(sql, new { RoleName = name }) > 0;
        }
    }
}